package com.dyd.smco.db.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.dyd.smco.db.domain.SmartCommunityStorage;
import com.dyd.smco.db.mapper.StorageMapper;
import com.dyd.smco.db.mybatis.IBaseServiceImpl;
import com.dyd.smco.db.service.IStorageService;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 文件存储表 服务实现类
 * </p>
 *
 * @author dyd
 * @since 2025-08-08
 */
@Service
@Primary
@CacheConfig(cacheNames = "smart_community_storage")
public class StorageServiceImpl extends IBaseServiceImpl<StorageMapper, SmartCommunityStorage> implements IStorageService {

    @Override
    @CacheEvict(allEntries = true)
    public int add(SmartCommunityStorage record) {
        return getBaseMapper().insert(record);
    }

    @Override
    @Cacheable(sync = true)
    public SmartCommunityStorage findById(Serializable id) {
        return getBaseMapper().selectById(id);
    }

    @Override
    @Cacheable(sync = true)
    public List<SmartCommunityStorage> queryAll(Wrapper<SmartCommunityStorage> queryWrapper) {
        return getBaseMapper().selectList(queryWrapper);
    }

    @Override
    @CacheEvict(allEntries = true)
    public boolean exists(Wrapper<SmartCommunityStorage> queryWrapper) {
        return getBaseMapper().exists(queryWrapper);
    }

    @Override
    @CacheEvict(allEntries = true)
    public boolean batchAdd(List<SmartCommunityStorage> list) {
        return saveBatch(list);
    }

    @Override
    @CacheEvict(allEntries = true)
    public int updateSelective(SmartCommunityStorage record) {
        return getBaseMapper().updateById(record);
    }

    @Override
    @CacheEvict(allEntries = true)
    public int updateVersionSelective(SmartCommunityStorage record) {
        return getBaseMapper().updateById(record);
    }

    @Override
    @CacheEvict(allEntries = true)
    public int deleteById(Serializable id) {
        return getBaseMapper().deleteById(id);
    }
}
